package logic

import (
	"context"
	"fmt"
	"weipinghui/models/mysql"

	"weipinghui/weipinghuirpc/internal/svc"
	"weipinghui/weipinghuirpc/weipinghuirpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectLogic) Perfect(in *weipinghuirpc.PerfectRequest) (*weipinghuirpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.User{
		Age:   in.Age,
		Email: in.Email,
	}
	err := mysql.DB.Debug().Where("id = ?", in.Id).Updates(&user).Error
	if err != nil {
		return nil, fmt.Errorf("信息完善失败")
	}
	return &weipinghuirpc.PerfectResponse{
		Id: int64(user.ID),
	}, nil
}
